package com.example.photo_album.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//使用WebMvcConfigurerAdapter可以来扩展SpringMVC的功能
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/page-login.html").setViewName("page-login");
        registry.addViewController("/").setViewName("page-login");
        registry.addViewController("/main.html").setViewName("main");
        registry.addViewController("/elements.html").setViewName("elements");
        registry.addViewController("/file-upload.html").setViewName("file-upload");
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册TestInterceptor拦截器
        registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/","/page-login.html","/error","/static/**","/user/login");       //添加不拦截路径
    }
}
